package com.sxkj.web.controller.version;

import com.sxkj.common.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import com.sxkj.entity.entity.version.Version;
import com.sxkj.service.version.VersionService;

/**
 * @author Zhang Xingliang
 * @description: 秤更新包版本表
 * @date 2019-12-31 13:25:40
 */
@RestController
@RequestMapping("/version")
public class VersionController {

    @Autowired
    private VersionService versionService;

    @ApiOperation(value = "根据主键查秤更新包版本表信息")
    @GetMapping(value = "/get/{id}")
    public ResponseResult get(@PathVariable String id) {
        try {
            Version version = versionService.get(id);
            return ResponseResult.success(version);
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

    @ApiOperation(value = "新增秤更新包版本表信息")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseResult save(@RequestBody Version version) {
        try {
            versionService.save(version);
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

    @ApiOperation(value = "删除秤更新包版本表信息")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseResult delete(@RequestBody Version version) {
        try {
            versionService.delete(version);
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

    @ApiOperation(value = "查询秤更新包版本表列表")
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    public ResponseResult findList(@RequestBody Version version) {
        try {
            return ResponseResult.success(versionService.findList(version));
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

    @ApiOperation(value = "查询秤更新包版本表列表")
    @RequestMapping(value = "/findPage", method = RequestMethod.POST)
    public ResponseResult findPage(@RequestBody Version version,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        try {
            PageInfo pageInfo = versionService.findPage(version, pageSize, pageNum);
            return ResponseResult.success(pageInfo);
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }

    @ApiOperation(value = "根据主键查秤更新包版本表信息")
    @GetMapping(value = "/info")
    public ResponseResult findNewVersion(@RequestBody Version version) {
        try {
            List<Map<String, String>> list = versionService.findNewVersion(version);
            return ResponseResult.success(list);
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }


    @ApiOperation(value = "新增秤更新包版本表信息")
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    public ResponseResult updateStatus(@RequestBody Version version) {
        try {
            versionService.save(version);
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.failure(e.toString());
        }
    }
}
